import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import type { AttackAndBuff, equipMessageType, randomProps } from '@/types/defaults'
type randomPropsId = {
  id: number
  data: randomProps
}
export const useCounterStore = defineStore('counter', {
  state: () => {
    return {
      iconList: [] as equipMessageType[][],
      descList: [] as randomPropsId[]
    }
  },
  actions: {
    addIconArray() {
      this.iconList.push([])
    },
    addIcon(equip: equipMessageType, index: number, index1: number) {
      this.iconList[index][index1] = equip
    },
    addDesc(id: number, data: randomProps) {
      this.descList.push({
        id,
        data: data
      })
    },
    descExist(id: number): number {
      return this.descList.findIndex((e) => e.id == id) ?? -1
    },
    findProp(id: number, propId: number): AttackAndBuff {
      const msg = this.descList.find((e) => e.id == id)
      let asw = msg?.data.randomPropsForCommon.find((e) => e.id == propId)
      asw = msg?.data.randomPropsForSelf.find((e) => e.id == propId) ?? asw
      asw = msg?.data.randomPropsForType.find((e) => e.id == propId) ?? asw
      return asw as AttackAndBuff
    }
  }
})
